package view;

import java.awt.Dimension;

import model.Model;
import model.visibility.PlayerView;
import controller.Controller;
import controller.KeyListeners.CursorKeyListener;
import controller.KeyListeners.KeyListenerSet;
import controller.KeyListeners.KeyboardListener;
import controller.KeyListeners.ViewChangeKeyListener;

public class View 
{ //  dimensions of the game
  private static final int width = 1024;
  private static final int height = 670;
  private final Dimension windowSize = new Dimension(width, height);
  private GameWindow window;
  private StartScreen start;
  private PlayerView playerView;
  /** Added for RunGame **/
  private Controller controller;
  private Model model;


  public View(Model _model, Controller _controller) 
  { model = _model;
  controller = _controller;
	  playerView = model.getPlayerView();
	  start = new StartScreen();
	  window = new GameWindow(windowSize,playerView,controller);
    window.add(start);
    //window.setControls(controller);
    window.setContentPane(start);
    window.setVisible(true);
  }
  public void tick()
  { 
	window.refreshAreaViewport();
	window.validate(); 
	window.repaint();
  }
  
  /** Added for Controller **/
  public void setController(Controller controller){ this.controller = controller; }
  public void setModel(Model model){ this.model = model;}
  
   public void addKeyListeners(KeyListenerSet keyListenerSet) {
	    KeyboardListener keyLSet[] = keyListenerSet.getKLSet();
		for(int i = 0; i < keyLSet.length;i++){
			window.addKeyListener(keyLSet[i]);
		}
		((CursorKeyListener) keyLSet[0]).attachAreaViewport(window.getAreaViewport());
		((ViewChangeKeyListener) keyLSet[6]).attachGameWindow(window);	
   }
}
